<?php
/**
 * Create By: PhpStorm
 * User: niechenguang
 * File: UpRank.php
 * Date: 2017/1/2
 * Time: 23:13
 */
namespace app\api\model\dao;

use think\Model;
use think\Db;

class RecommendRank extends Model
{
    protected $table = 'recommend_rank';

    protected $pk = 'id';

    /**
     * 添加推举
     *
     */
    public function addRecommendRank($userid, $username, $rank, $reason)
    {
        $sql = sprintf("insert into %s(userid, user_name, rank, reason, create_time) values(%d,'%s',%d,'%s',%d) on duplicate key update rank=%d", $this->table, $userid, $username, $rank, $reason, time(), $rank);
        return Db::table($this->table)->query($sql);
    }

    /**
     * 获取推举榜
     *
     */
    public function delRecommendRankByid($id)
    {
        return Db::table($this->table)->where(['id' => ['=', $id]])->delete();
    }

    /**
     * 获取推举榜
     *
     */
    public function getRecommendRank($offset = 0, $limit = 10)
    {
        return Db::table($this->table)->limit($offset, $limit)->order('rank desc')->select();
    }

    /**
     * @return \think\paginator\Collection
     */
    public function RecommendRankPage()
    {
        return $this->paginate(10);
    }

}
